<?php
/**
 * Created by PhpStorm.
 * User: wanglidong
 * Date: 16/3/17
 * Time: 23:42
 */
namespace Admin\Controller;
class IndexController extends BaseController {

    public function index() {
       //图书库存
        $stock['rent'] = M("Book")->where("is_del=0")->sum('stock_rent');
        $stock['buy'] = M("Book")->where("is_del=0")->sum('stock_buy');
        $stock['total'] = $stock['buy'] + $stock['rent'];
        //订单数量
        $order['total']=M("Pay")->where("status > -1")->count();
        $order['pay']=M("Pay")->where("status =1")->count();
        $order['percent']=round($order['pay'] / $order['total']*100,0);
        //用户数
        $user['general']=M("User")->count();
        $user['vip']=M("Card")->count();
        $user['percent']=round($user['vip'] / $user['general']*100,0);

        //最新订单
        $orderlist=M("Order_book")->alias("a")->join("user b on a.user_id=b.user_id","left")->join("card c on a.user_id=c.user_id","left")->field("a.*,b.headimgurl,b.nickname,c.card_id")->limit("0,8")->order("create_time desc")->select();

        //最新评论
        $comment=M("Order_book_apprise")->alias("a")->join("user b on a.user_id=b.user_id","left")->field("a.*,b.headimgurl,b.nickname")->limit("0,3")->order("create_time desc")->select();

        $this->assign("comment",$comment);
        $this->assign("orderlist",$orderlist);
        $this->assign("user",$user);
        $this->assign("stock" , $stock);
        $this->assign("order" , $order);
        $this->display();
    }
}